/**
 * 
 */
package com.wzl.qs;

import android.text.format.Time;

/**
 * @author Wu Wei
 * 
 */
public class DateTimeUtils {
	private static String padZeroIfNecessary(int i) {
		if (i < 10) {
			return "0" + i;
		} else {
			return "" + i;
		}
	}

	public static String getDate(Time tt) {
		int imonth = tt.month + 1;
		String month = padZeroIfNecessary(imonth);
		int iday = tt.monthDay;
		String day = padZeroIfNecessary(iday);
		String date = "" + tt.year + "-" + month + "-" + day;
		return date;
	}

	public static String getTime(Time tt) {
		int ihour = tt.hour;
		String hour = padZeroIfNecessary(ihour);
		int iminute = tt.minute;
		String minute = padZeroIfNecessary(iminute);
		int isecond = tt.second;
		String second = padZeroIfNecessary(isecond);
		return hour + ":" + minute + ":" + second;
	}

	public static String getToday() {
		Time tt = new Time();
		tt.setToNow();
		return DateTimeUtils.getDate(tt);
	}

	public static String getNow() {
		Time tt = new Time();
		tt.setToNow();
		return DateTimeUtils.getTime(tt);
	}
}
